package com.king.utils;

import com.king.annotation.Autowired;
import com.king.annotation.Service;

import java.sql.SQLException;

/**
 * @ClassName: TransactionManager
 * @Description: 事务管理
 * @Author: wangchangyong
 * @Date: 2020/4/7 14:08
 * @Version: 1.0.0
 **/
@Service
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    // public void setConnectionUtils(ConnectionUtils connectionUtils) {
    //     this.connectionUtils = connectionUtils;
    // }

    // 开启手动事务控制
    public void beginTransaction() throws SQLException {
        connectionUtils.getCurrentThreadConn().setAutoCommit(false);
    }

    // 提交事务
    public void commit() throws SQLException {
        connectionUtils.getCurrentThreadConn().commit();
    }

    // 回滚事务
    public void rollback() throws SQLException {
        connectionUtils.getCurrentThreadConn().rollback();
    }
}
